package com.hd.controller;

import com.alibaba.fastjson.JSON;
import com.hd.pojo.Book;
import com.hd.service.BookService;
import com.hd.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;

    @RequestMapping("/allBook")
    @ResponseBody
    public String allBook(int page,int limit){
        JsonData jsonData=bookService.allBook(page,limit);
        return JSON.toJSONString(jsonData);
    }

    @RequestMapping("/delBook")
    @ResponseBody
    public String delBook(int bookId){
        JsonData jsonData=bookService.delBook(bookId);
        return JSON.toJSONString(jsonData);
    }

    @RequestMapping("/saveBook")
    @ResponseBody
    public String saveBook(Book book ){
        JsonData jsonData=bookService.saveBook(book);
        return JSON.toJSONString(jsonData);
    }
}
